home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / NONPORT.ZIP / WINPRINT.C < prev    next >
Text File  |  1992-11-21  |  5KB  |  142 lines

  1. #ifndef NO_MEMORY_H
  2. #define        CURSES_LIBRARY  1
  3. #endif
  4. #include <curses.h>
  5. #undef winPDC_print
  6.  
  7. #ifndef NDEBUG
  8. char *rcsid_winprint = "$Header: c:/curses/nonport/RCS/winprint.c%v 2.0 1992/11/15 03:18:31 MH Rel $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14. #define PRINT  0
  15. #define INIT   1
  16. #define READ   2
  17.  
  18. /*man-start*********************************************************************
  19.  
  20.   win_print()  - print contents of window to LPT1
  21.  
  22.   PDCurses Description:
  23.        Prints the contents of the passed window or pad to LPT1:.  All
  24.        attributes are ignored.  Newlines will be appended to the end
  25.        of all win->_y[]s.  The caller must supply the compiler-
  26.        dependent port number.
  27.  
  28.   PDCurses Return Value:
  29.        Return Status:  bit 0   0x01    Device Time Out
  30.                        bit 1   0x02    Bad WINDOW* passed
  31.                        bit 2   0x04    Unable to malloc memory
  32.                        bit 3   0x08    I/O Error
  33.                        bit 4   0x10    Selected
  34.                        bit 5   0x20    Out of paper
  35.                        bit 6   0x40    Acknowledge
  36.                        bit 7   0x80    Not Busy
  37.  
  38.        A return value of 0 indicates success.
  39.  
  40.   PDCurses Errors:
  41.        It is an error to pass a NULL WINDOW pointer.
  42.  
  43.   Portability:
  44.        PDCurses        int win_print( WINDOW* win, int port );
  45.  
  46. **man-end**********************************************************************/
  47.  
  48. int    win_print(WINDOW *win, int port)
  49. {
  50. #if    defined( DOS )
  51.        char   *text;
  52.        int     i;
  53.        int     j;
  54.        int     status;
  55.        int     retry = 0;
  56. extern void*   (*mallc)();             /* ptr to some malloc(size)     */
  57. extern void*   (*callc)();             /* ptr to some ecalloc(num,size)*/
  58. extern void    (*fre)();               /* ptr to some free(ptr)        */
  59.  
  60.        if (win == (WINDOW *)NULL)
  61.                return( 0x02 );
  62.  
  63.        status = PDC_print(READ, 0, port);
  64.  
  65.        if (((status & 0x20) != 0) || ((status & 0x08) != 0))
  66.                return( status );
  67.        /*
  68.         * Print the window title First
  69.         */
  70.        text = win->_title;
  71.        while (text != (char *)NULL)
  72.        {
  73.                status = PDC_print(PRINT, (int) *text, port);
  74.                while ((status & 0x80) == 0x00)
  75.                {
  76.                        if ((status & 0x01) == 0x01)
  77.                        {
  78.                                retry++;
  79.                                if (retry > 10)
  80.                                        return( status );
  81.                        }
  82.                        if (((status & 0x20) == 0x20) ||
  83.                            ((status & 0x10) == 0x00) ||
  84.                            ((status & 0x08) == 0x08))
  85.                        {
  86.                                return( status );
  87.                        }
  88.                        status = PDC_print(READ, 0, port);
  89.                }
  90.        }
  91.        PDC_print(PRINT, '\r', port);
  92.        PDC_print(PRINT, '\n', port);
  93.        PDC_print(PRINT, '\n', port);
  94.        text = (*mallc)(win->_maxx);
  95.        if (text != (char *)NULL)
  96.        {
  97.                for (i = 0; i < win->_maxy; i++)
  98.                {
  99.                        for (j = 0; j < win->_maxx; j++)
  100.                        {
  101.                                status = PDC_print(PRINT, (int) win->_y[i][j], port);
  102.                                while ((status & 0x80) == 0x00)
  103.                                {
  104.                                        if ((status & 0x01) == 0x01)
  105.                                        {
  106.                                                retry++;
  107.                                                if (retry > 10)
  108.                                                {
  109.                                                        (*fre)(text);
  110.                                                        return( status );
  111.                                                }
  112.                                        }
  113.                                        if (((status & 0x20) == 0x20) ||
  114.                                            ((status & 0x10) == 0x00) ||
  115.                                            ((status & 0x08) == 0x08))
  116.                                        {
  117.                                                (*fre)(text);
  118.                                                return( status );
  119.                                        }
  120.  
  121.                                        status = PDC_print(READ, 0, port);
  122.                                }
  123.                                retry = 0;
  124.  
  125.                        }
  126.                        PDC_print(PRINT, '\r', port);
  127.                        PDC_print(PRINT, '\n', port);
  128.                }
  129.                PDC_print(PRINT, '\f', port);
  130.                (*fre)(text);
  131.                return( 0x00 );
  132.        }
  133.        return( 0x04 );
  134. #endif
  135. #if    defined( HC ) && defined( FLEXOS )
  136.        return( 0x03 );
  137. #endif
  138. #ifdef OS2
  139.        return( 0x03 );
  140. #endif
  141. }
  142.